<template>
	<view class="load" v-if="!load">
		<u-loading-icon mode="circle" inactive-color="#fff" text="正在加载..." vertical></u-loading-icon>
	</view>
	<view v-else>
		<x-scroll :fixed="true" @onRefresh="onRefresh" @scrolltolower="scrolltolower" :refresh="_freshing">
			<view class="list ">
				<view class="item wap">
					<view class="con">
						<view class="txt">日期</view>
						<view class="txt">微信</view>
						<view class="txt">iOS</view>
						<view class="txt">安卓</view>
						<view class="summary">合计</view>
					</view>
				</view>
				<view v-for="item in list" :key="item.ID">
					<view class="item wap">
						<view class="con">
							<view class="txt">{{item.CreateTime}}</view>
							<view class="txt">{{item.Wx_Qty}} </view>
							<view class="txt">{{item.iOS_Qty}} </view>
							<view class="txt">{{item.Android_Qty}} </view>
							<view class="summary">{{item.Qty}} </view>
						</view>

					</view>
				</view>
			</view>

		</x-scroll>
	</view>

</template>

<script>
	export default {
		data() {
			return {
				load: false,
				_freshing: true,
				list: [],
				searchValue: '',
				PageIndex: 1, //页码
				PageSize: 30, //请求条数
				isMore: true
			}
		},
		onLoad(args) {
			this.init();
		},
		onShow() {

		},
		methods: {
			clearRepetition(arr, key = "ID") {
				let newArr = [];
				arr.forEach(item => {
					let index;
					let check = newArr.every((newItem, i) => {
						if (item[key] !== newItem[key]) {
							index = -1;
							return true;
						} else {
							index = i;

							return false;
						}
					})
					if (check) {
						newArr.push(item);
					} else {
						newArr.splice(index, 1, item);
					}

				})
				console.log('newArr', newArr)
				return newArr;
			},
			onRefresh() {
				this.PageIndex = 1;
				this.init();
			},
			//滚动到底部触发
			async scrolltolower() {
				if (this.isMore) {
					this.PageIndex++;
					this.init();
				}
			},

			async init() {
				let res = await this.$api.post('/Manage/DayActMembers', {
					PageIndex: this.PageIndex,
					PageSize: this.PageSize
				});



				let list1 = this.list.concat(res.data)


				this.list = this.clearRepetition(list1, "ID");


				this.isMore = Array.isArray(res.data) && res.data.length >= this.PageSize;

				this.load = true;

			},


		},
		computed: {


		}
	}
</script>

<style lang="scss">
	.list {
		.item {
			display: flex;
			height: 80rpx;
			align-items: center;

			.con {
				padding-left: 20rpx;
				flex-flow: row nowrap;
				display: flex;
				justify-content: space-between;
				width: 100%;

				.txt {
					margin-top: 10rpx;
					width:20%;
					text-align: center;
				}
				
				.summary {
					margin-top: 10rpx;
					width:20%;
					text-align: center;
					
					color:#ff0;
				}
			}

		}


	}
</style>